package com.plian.system.controller.pf;

import com.plian.Tools.Func;
import com.plian.Tools.StringPool;
import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.annotation.LogOperation;
import com.plian.system.config.Resubmit;
import com.plian.system.entity.pf.BaseEvaluationScore;
import com.plian.system.model.CommonCode;
import com.plian.system.model.ListResult;
import com.plian.system.model.R;
import com.plian.system.mybatis.support.Query;
import com.plian.system.service.pf.IBaseEvaluationScoreService;
import com.plian.system.vo.pf.BaseEvaluationScoreVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: Take-off
 * @Description: TODO
 * @Date: 2023/1/28 3:32 PM
 * @Version: 1.0
 **/
@RestController
@AllArgsConstructor
@RequestMapping("api/evaluationscore")
@Api(value = "BaseEvaluationScoreController", tags = "履职成效-企业自评 控制器")
public class BaseEvaluationScoreController extends BaseController {

    private final IBaseEvaluationScoreService baseEvaluationScoreService;

    @PostMapping("/detail")
    @ApiOperation(value = "详情", notes = "传入 baseEvaluationScore")
    public R<BaseEvaluationScoreVO> detail(@RequestBody BaseEvaluationScore baseEvaluationScore) {
        return baseEvaluationScoreService.getDetailObj(baseEvaluationScore);
    }

    @PostMapping("/list")
    @ApiOperation(value = "分页", notes = "传入query")
    public ListResult<BaseEvaluationScoreVO> list(@RequestBody Query query) {
        ListResult<BaseEvaluationScoreVO> listResult = baseEvaluationScoreService.list(query);
        return listResult;
    }

    @PostMapping("/submit")
    @ApiOperation(value = "新增或修改", notes = "baseEvaluationScore")
    @Resubmit(delaySeconds = 0)
    @LogOperation("履职成效-企业自评-提交")
    public R<BaseEvaluationScore> submit(@Valid @RequestBody BaseEvaluationScore baseEvaluationScore) {
        boolean result = baseEvaluationScoreService.submit(baseEvaluationScore);
        return result ? R.data(baseEvaluationScore) : new R(CommonCode.FAIL);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除", notes = "传入 ids")
    @LogOperation("履职成效-企业自评-删除")
    public R remove(@RequestBody PageData pd) {
        List<String> ids = (List<String>) pd.get("ids");
        return baseEvaluationScoreService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA)))
                ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
    }

}
